<?php

namespace App\Listeners;

use App\Events\OrderChildAllDone;
use App\Models\SemiFinishProduct;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;

class AddSemiFinishProduct
{
    /**
     * Create the event listener.
     *
     * @return void
     */

    public function __construct()
    {
    }

    /**
     * Handle the event.
     *
     * @param  \App\Providers\OrderChildAllDone  $event
     * @return void
     */
    public function handle(OrderChildAllDone $event)
    {
        //将完成的订单添加到半成品库
        Log::channel('dblog')->info('将完成的订单添加到半成品库,order_id:'.$event->order->id);
        $order_id = $event->order->id;
//        $semiFinishProduct = new SemiFinishProduct();
//        $semiFinishProduct->order_id = $order_id;
//        $semiFinishProduct->finish_time = date("Y-m-d H:i:s");
//        $semiFinishProduct->save();
        SemiFinishProduct::updateOrCreate(['order_id'=>$order_id],['order_id'=>$order_id,'finish_time'=>date("Y-m-d H:i:s")]);
    }
}
